/*
 * Copyright (C) 2010 mAPPn.Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mol.market.common.network;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Build;
import android.text.TextUtils;

import com.mol.market.Constants;
import com.mol.market.Session;
import com.mol.market.common.codec.binary.Base64;
import com.mol.market.common.codec.digest.DigestUtils;
import com.mol.market.common.network.ApiAsyncTask.ApiRequestListener;
import com.mol.market.common.util.CashbackManager.CashbackTask;
import com.mol.market.common.util.DBUtils;
import com.mol.market.common.util.SecurityUtil;
import com.mol.market.common.util.Utils;
import com.mol.market.common.vo.CardInfo;

/**
 * aMarket API utility class
 *
 * @author andrew.wang
 * @date 2010-10-29
 * @since Version 0.4.0
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class MarketAPI {

    /**
     * 机锋市场API host地址
     */
    public static final String API_BASE_URL =
            // real host
//    "http://api.gfan.com/";
            // test host
//            "http://117.79.80.22/";
//    "http://117.79.146.102:8080/";
    "http://54.254.137.187/";
    
    /**
     * 机锋市场API地址
     */
    public static final String API_HOST_JAVA =
            API_BASE_URL + "market/api/";
//           API_BASE_URL + "market/api/";
//     "http://10.16.17.159:8080/market.gfan.com/api/";
//    		"http://117.79.146.102:8080/";

    /**
     * 返利平台API地址
     */
    public static final String API_HOST_REBATE =
            API_BASE_URL + "rebate/cpa/";
//        "http://117.79.80.22/rebate/cpa/";
//        "http://10.16.17.104:8080/rebate.gfan.com/cpa/";

    /**
     * 用户中心API地址
     */
    public static final String API_UCENTER_HOST = API_BASE_URL
            // real host
            + "uc1/common/";
    // test host
    // + "uc/common/";
    // TEST
    // "http://117.79.80.12/uc1/common/";
//    		+ "uc1/";

    public static final String BBS_SEARCH_API = "http://search.gfan.com/search/search/luntanAttJk";
    // "http://10.16.8.232:8080/search/search/luntanAttJk";

    // 机锋市场搜索关键词推荐
    public static final String MARKET_SEARCH_API = "http://search.gfan.com/search/search/marketHotWords?q=";

    // User Center URL HOST
    public static final String API_HOST_CLOUD = "http://passport.gfan.com/gfan_center/";

    /**
     * Log API
     */
    private final static String LOG_HOST =
            // 生产环境
            "http://logcollect.gfan.com";
    // 测试环境
    // "http://117.79.80.12";

    // 机锋市场 API URLS
    /* package */static final String[] API_URLS = {
            // ACTION_LOGIN
            API_UCENTER_HOST + "login",
            // ACTION_REGISTER
            API_UCENTER_HOST + "register",
            // ACTION_GET_COMMENTS
            API_HOST_JAVA + "getComments",
            // ACTION_ADD_COMMENT
            API_HOST_JAVA + "addComment",
            // ACTION_ADD_RATING
            API_HOST_JAVA + "addRating",
            // ACTION_PURCHASE_PRODUCT
            API_BASE_URL + "sdk/pay/purchaseProduct",
            // ACTION_GET_CONSUMESUM
            API_BASE_URL + "sdk/pay/getConsumeSum",
            // ACTION_SYNC_BUYLOG
            API_HOST_JAVA + "syncBuyLog",
            // ACTION_GET_MYRATING
            API_HOST_JAVA + "getMyRating",
            // ACTION_GET_CONSUME_DETAIL
            API_BASE_URL + "sdk/pay/getConsumeDetail",
            // ACTION_GET_TOPIC
            API_HOST_JAVA + "getTopic",
            // ACTION_SEARCH
            API_HOST_JAVA + "search",
            // ACTION_GET_PRODUCTS
            API_HOST_JAVA + "getProducts",
            // ACTION_GET_RECOMMEND_PRODUCTS
            API_HOST_JAVA + "getRecommendProducts",
            // ACTION_GET_PRODUCT_DETAIL
            API_HOST_JAVA + "getProductDetail",
            // ACTION_GET_DOWNLOAD_URL
            API_HOST_JAVA + "getDownloadUrl",
            // ACTION_GET_HOME_RECOMMEND
            API_HOST_JAVA + "getHomeRecommend",
            // ACTION_CHECK_NEW_VERSION
            API_HOST_JAVA + "checkNewVersion",
            // ACTION_GET_CATEGORY
            API_HOST_JAVA + "getCategory",
            // ACTION_CHECK_UPGRADE
            API_HOST_JAVA + "checkUpgrade",
            // ACTION_BIND_ACCOUNT
            API_HOST_CLOUD + "?mo=cloud_phone&do=addDev",
            // ACTION_GET_BALANCE
            API_UCENTER_HOST + "query_balance",
            // ACTION_GET_PAY_LOG
            API_BASE_URL + "sdk/pay/chargeConsumeLog",
            // ACTION_CHARGE
            API_BASE_URL + "pay/szf/servlet/rechargeRequest",
            // ACTION_SYNC_CARDINFO
            API_BASE_URL + "pay/szf/getCardConfigServlet",
            // ACTION_QUERY_CHARGE_BY_ORDERID
            API_BASE_URL + "pay/szf/sdk/queryServlet",
            // ACTION_QUERY_CHARGE
            API_UCENTER_HOST + "query_charge_log_list",
            // ACTION_SYNC_APPS
            API_HOST_JAVA + "syncApps",
            // ACTION_CHECK_NEW_SPLASH
            API_HOST_JAVA + "checkNewSplash",
            // ACTION_UNBIND
            API_HOST_CLOUD + "?mo=cloud_phone&do=delDev&uid=",
            // ACTION_GET_DETAIL
            API_HOST_JAVA + "getDetail",
            // ACTION_GET_ALIPAY_ORDER_INFO
            API_BASE_URL + "pay/szf/servlet/businessProcess.do",
            // ACTION_QUERY_ALIPAY_RESULT
            API_BASE_URL + "pay/szf/servlet/businessProcess.do",
            // ACTION_GET_SEARCH_KEYWORDS
            API_HOST_JAVA + "getKeywords",
            // ACTION_GET_TOP_RECOMMEND
            API_HOST_JAVA + "getTopRecommend",
            // ACTION_GET_RANK_BY_CATEGOR
            API_HOST_JAVA + "getRankByCategory",
            // ACTION_GET_GROW_FAST
            API_HOST_JAVA + "getGrowFast",
            // ACTION_GET_ALL_CATEGORY
            API_HOST_JAVA + "getAllCategory",
            // ACTION_GET_REQUIRED
            API_HOST_JAVA + "getRequired",
            // ACTION_BBS_SEARCH
            BBS_SEARCH_API,
            // ACTION_CHECK_LOG_LEVEL
            LOG_HOST + "/marketExceptionReport/api/getModuleLogLevel",
            // ACTION_INSERT_LOG
            LOG_HOST + "/marketExceptionReport/api/insertModuleExceptionLog",
            // ACTION_GET_MASTER_RECOMMEND
            API_HOST_JAVA + "masterRecommend",
            // ACTION_GET_MASTER_RECOMMEND_APPS
            API_HOST_JAVA + "masterRecommendApps",
            // ACTION_DOWN_REPORT
            API_HOST_JAVA + "downReport",
            // ACTION_GET_DISCUSS
            API_HOST_JAVA + "masterRecommendDiscuss",
            // ACTION_ADD_DISCUSS
            API_HOST_JAVA + "addMasterRecommendDiscuss",
            // ACTION_ADD_RECOMMEND_RATING
            API_HOST_JAVA + "addMasterRecommendRating",
            // ACTION_GET_RECOMMEND_RATING
            API_HOST_JAVA + "masterRecommendRating",
            // ACTION_GET_RECOMMEND_NOTIFICATION
            API_HOST_JAVA + "notification",
            // ACTION_GET_MASTER_CONTAINS
            API_HOST_JAVA + "masterContainsApp",
            // ACTION_GET_RECOMMEND_BY_APP
            API_HOST_JAVA + "recommendByApp",
            // ACTION_FOLLOW_MASTER
            API_HOST_JAVA + "followMasterRecommend",
            // ACTION_GET_FOLLOWED_RECOMMEND
            API_HOST_JAVA + "followedMasterRecommend",
            // ACTION_GET_HOME_MASTER_RECOMMEND
            API_HOST_JAVA + "homeMasterRecommend",
            // ACTION_MARK_READ
            API_HOST_JAVA + "masterRecommendNewApps",
            // ACTION_IFTTT_REPORT
            API_HOST_JAVA + "notificationReport",
            // ACTION_PAID_RANK
            API_HOST_JAVA + "sellRank",
            // ACTION_GET_MESSAGE
            API_HOST_JAVA + "getMsgs",
            // ACTION_GET_SEARCH_RECOMMEND
            MARKET_SEARCH_API,
            // ACTION_GET_EXCHANGE_BALANCE
            API_HOST_REBATE + "getBalance",
            // ACTION_GET_EXCHANGE_BANNER
            API_HOST_REBATE + "getHomeBanner",
            // ACTION_GET_EXCHANGE_HOME_TASK
            API_HOST_REBATE + "getHomeTask",
            // ACTION_GET_EXCHANGE_TASK_DETAIL
            API_HOST_REBATE + "getTaskDetail",
            // ACTION_GET_EXCHANGE_TYPE
            API_HOST_REBATE + "getExchangeType",
            // ACTION_GET_EXCHANGE_GOODS
            API_HOST_REBATE + "getExchangeGoods",
            // ACTION_GET_EXCHANGE_DETAIL
            API_HOST_REBATE + "getExchangeDetail",
            // ACTION_GET_EXCHANGE_REWARD
            API_HOST_REBATE + "getRewardDetail",
            // ACTION_EXCHANGE
            API_HOST_REBATE + "exchange",
            // ACTION_REPORT_INSTALLATION
            API_HOST_REBATE + "reportInstall",
            // ACTION_REQUEST_REWARD
            API_HOST_REBATE + "requestReward",
            // ACTION_REQUEST_CATEGORY_TAGS
            API_HOST_JAVA + "allGroupTags",
            // ACTION_REQUEST_ACTION_GET_TAGS_DETAILS
            API_HOST_JAVA + "tagApps",
            // ACTION_REQUEST_ACTION_GET_TAGS_IN_DETAILS
            API_HOST_JAVA + "tagsByApp",
            // ACTION_RECOMMEND_BY_USER
            API_HOST_JAVA + "recommendByUser",
            // ACTION_THRID_LOGIN
            API_UCENTER_HOST + "thirdLogin",
            // ACTION_GET_HISTORY_INSTALL
            API_HOST_JAVA + "getHistoryInstall",
            API_HOST_JAVA + "insertHistoryInstall"
    };

    /**
     * 登录
     */
    public static final int ACTION_LOGIN = 0;
    /**
     * 注册
     */
    public static final int ACTION_REGISTER = 1;
    /**
     * 获取评论
     */
    public static final int ACTION_GET_COMMENTS = 2;
    /**
     * 添加评论
     */
    public static final int ACTION_ADD_COMMENT = 3;
    /**
     * 添加星级
     */
    public static final int ACTION_ADD_RATING = 4;
    /**
     * 购买软件
     */
    public static final int ACTION_PURCHASE_PRODUCT = 5;
    /**
     * 获取消费额
     */
    public static final int ACTION_GET_CONSUMESUM = 6;
    /**
     * 获取消费记录
     */
    public static final int ACTION_SYNC_BUYLOG = 7;
    /**
     * 获取我的评级
     */
    public static final int ACTION_GET_MYRATING = 8;
    /**
     * 获取消费明细
     */
    public static final int ACTION_GET_CONSUME_DETAIL = 9;
    /**
     * 获取专题
     */
    public static final int ACTION_GET_TOPIC = 10;
    /**
     * 搜索
     */
    public static final int ACTION_SEARCH = 11;
    /**
     * 获取商品
     */
    public static final int ACTION_GET_PRODUCTS = 12;
    /**
     * 获取专题推荐商品
     */
    public static final int ACTION_GET_RECOMMEND_PRODUCTS = 13;
    /**
     * 获取应用详细
     */
    public static final int ACTION_GET_PRODUCT_DETAIL = 14;
    /**
     * 获取应用下载链接
     */
    public static final int ACTION_GET_DOWNLOAD_URL = 15;
    /**
     * 获取首页推荐列表
     */
    public static final int ACTION_GET_HOME_RECOMMEND = 16;
    /**
     * 检查（机锋市场）更新
     */
    public static final int ACTION_CHECK_NEW_VERSION = 17;
    /**
     * 获取分类
     */
    public static final int ACTION_GET_CATEGORY = 18;
    /**
     * 检查（应用）更新
     */
    public static final int ACTION_CHECK_UPGRADE = 19;
    /**
     * 绑定账户（云推送）
     */
    public static final int ACTION_BIND_ACCOUNT = 20;
    /**
     * 获取余额
     */
    public static final int ACTION_GET_BALANCE = 21;
    /**
     * 获取消费记录
     */
    public static final int ACTION_GET_PAY_LOG = 22;
    /**
     * 充值
     */
    public static final int ACTION_CHARGE = 23;
    /**
     * 同步卡信息
     */
    public static final int ACTION_SYNC_CARDINFO = 24;
    /**
     * 获取支付记录
     */
    public static final int ACTION_QUERY_CHARGE_BY_ORDERID = 25;
    /**
     * 获取支付记录
     */
    public static final int ACTION_QUERY_CHARGE = 26;
    /**
     * 获取用户安装应用列表
     */
    public static final int ACTION_SYNC_APPS = 27;
    /**
     * 检查SPLASH更新
     */
    public static final int ACTION_CHECK_NEW_SPLASH = 28;
    /**
     * 解除绑定（运推送）
     */
    public static final int ACTION_UNBIND = 29;
    /**
     * 获取产品详细信息（通过包名）
     */
    public static final int ACTION_GET_DETAIL = 30;
    /**
     * 获取支付宝订单信息
     */
    public static final int ACTION_GET_ALIPAY_ORDER_INFO = 31;
    /**
     * 获取支付宝充值结果
     */
    public static final int ACTION_QUERY_ALIPAY_RESULT = 32;
    /**
     * 获取搜索热词
     */
    public static final int ACTION_GET_SEARCH_KEYWORDS = 33;
    /**
     * 获取首页顶部推荐
     */
    public static final int ACTION_GET_TOP_RECOMMEND = 34;
    /**
     * 获取排行榜
     */
    public static final int ACTION_GET_RANK_BY_CATEGORY = 35;
    /**
     * 获取增长最快排行列表
     */
    public static final int ACTION_GET_GROW_FAST = 36;
    /**
     * 获取所有分类列表
     */
    public static final int ACTION_GET_ALL_CATEGORY = 37;
    /**
     * 获取装机必备列表
     */
    public static final int ACTION_GET_REQUIRED = 38;
    /**
     * BBS Search API
     */
    public static final int ACTION_BBS_SEARCH = 39;
    /**
     * 检查LOG级别 API
     */
    public static final int ACTION_CHECK_LOG_LEVEL = 40;
    /**
     * 提交LOG API
     */
    public static final int ACTION_INSERT_LOG = 41;
    /**
     * 获取玩家推荐列表
     */
    public static final int ACTION_GET_MASTER_RECOMMEND = 42;
    /**
     * 获取玩家推荐应用
     */
    public static final int ACTION_GET_MASTER_RECOMMEND_APPS = 43;
    /**
     * 下载日志
     */
    public static final int ACTION_DOWN_REPORT = 44;
    /**
     * 获取推荐主题的讨论
     */
    public static final int ACTION_GET_DISCUSS = 45;
    /**
     * 添加讨论的条目
     */
    public static final int ACTION_ADD_DISCUSS = 46;
    /**
     * 添加推荐主题的评级
     */
    public static final int ACTION_ADD_RECOMMEND_RATING = 47;
    /**
     * 获取推荐主题的评级
     */
    public static final int ACTION_GET_RECOMMEND_RATING = 48;
    /**
     * 通知栏推荐
     */
    public static final int ACTION_GET_RECOMMEND_NOTIFICATION = 49;
    /**
     * 发现收录应用达人
     */
    public static final int ACTION_GET_MASTER_CONTAINS = 50;
    /**
     * 与应用相关的推荐列表
     */
    public static final int ACTION_GET_RECOMMEND_BY_APP = 51;
    /**
     * 关注达人推荐的主题
     */
    public static final int ACTION_FOLLOW_MASTER = 52;
    /**
     * 已关注达人推荐的主题
     */
    public static final int ACTION_GET_FOLLOWED_RECOMMEND = 53;
    /**
     * 获得首页的达人推荐专题
     */
    public static final int ACTION_GET_HOME_MASTER_RECOMMEND = 54;
    /**
     * 标记达人推荐新应用已读
     */
    public static final int ACTION_MARK_READ = 55;
    /**
     * IFTTT回报
     */
    public static final int ACTION_IFTTT_REPORT = 56;
    /**
     * 收费排行榜
     */
    public static final int ACTION_PAID_RANK = 57;
    /**
     * 定制推送消息
     */
    public static final int ACTION_GET_MESSAGE = 58;
    /**
     * 搜索关键词推荐
     */
    public static final int ACTION_GET_SEARCH_RECOMMEND = 59;

    // -----> 返利平台
    /**
     * 获取返利余额
     */
    public static final int ACTION_GET_EXCHANGE_BALANCE = 60;
    /**
     * 获取返利首页推广图
     */
    public static final int ACTION_GET_EXCHANGE_BANNER = 61;
    /**
     * 获取返利首页任务列表
     */
    public static final int ACTION_GET_EXCHANGE_HOME_TASK = 62;
    /**
     * 获取返利任务详细
     */
    public static final int ACTION_GET_EXCHANGE_TASK_DETAIL = 63;
    /**
     * 获取返利兑换类型
     */
    public static final int ACTION_GET_EXCHANGE_TYPE = 64;
    /**
     * 获取返利兑换物品
     */
    public static final int ACTION_GET_EXCHANGE_GOODS = 65;
    /**
     * 获取返利兑换记录明细
     */
    public static final int ACTION_GET_EXCHANGE_DETAIL = 66;
    /**
     * 获取返利收入明细
     */
    public static final int ACTION_GET_EXCHANGE_REWARD = 67;
    /**
     * 返利兑换
     */
    public static final int ACTION_EXCHANGE = 68;
    /**
     * 报告安装事件
     */
    public static final int ACTION_REPORT_INSTALLATION = 69;
    /**
     * 申请返利
     */
    public static final int ACTION_REQUEST_REWARD = 70;

    /**
     * 获得标签列表
     */
    public static final int ACTION_GET_CATEGORY_TAGS = 71;
    /**
     * 获得标签详情页
     */
    public static final int ACTION_GET_TAGS_DETAILS = 72;
    /**
     * 在详情页获取标签
     */
    public static final int ACTION_GET_TAGS_IN_DETAILS = 73;
    /**
     * 猜你喜欢
     */
    public static final int ACTION_RECOMMEND_BY_USER = 74;
    /**
     * 注册第三方登录信息
     */
    public static final int ACTION_THRID_LOGIN = 75;
    /**
     * 获取已安装应用列表
     */
    public static final int ACTION_GET_HISTORY_INSTALL = 76;
    /**
     * 插入已安装应用列表
     */
    public static final int ACTION_INSERT_HISTORY_INSTALL = 77;

    /**
     * 报告安装事件<br>
     * 安装来源类型
     * 0:非返利客户端安装
     * 1:返利客户端安装
     */
    public static void reportInstallation(final Context context,
            ApiRequestListener handler, ArrayList<CashbackTask> list) {

        final ArrayList<HashMap<String, Object>> paramList =
                new ArrayList<HashMap<String, Object>>(list.size());

        for (CashbackTask task : list) {
            HashMap<String, Object> param = new HashMap<String, Object>(2);
            param.put("pkg", SecurityUtil.encryptRebateInfo(task.packageName));
            param.put("from", SecurityUtil.encryptRebateInfo(String.valueOf(task.source)));
            paramList.add(param);
        }

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("installation", paramList);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_REPORT_INSTALLATION, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_REPORT_INSTALLATION, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 申请返利
     */
    public static void requestReward(final Context context,
            ApiRequestListener handler, String pkgName) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);

        params.put("pkg", SecurityUtil.encryptRebateInfo(pkgName));

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_REQUEST_REWARD, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_REQUEST_REWARD, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }


    /**
     * 获取返利余额
     */
    public static void getExchangeBalance(final Context context,
            ApiRequestListener handler) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_BALANCE, handler, null).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_BALANCE, handler, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取返利推广图
     */
    public static void getExchangeBanner(final Context context,
            ApiRequestListener handler) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_BANNER, handler, null).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_BANNER, handler, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取返利任务列表
     */
    public static void getExchangeTask(final Context context,
            ApiRequestListener handler, int startPosition, int size) {

        final HashMap<String, Object> params = new HashMap<String, Object>(2);

        params.put("start_position", startPosition);
        params.put("size", size);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_HOME_TASK, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_HOME_TASK, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取返利任务详细
     */
    public static void getExchangeTaskDetail(final Context context,
            ApiRequestListener handler, String id) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);

        params.put("id", id);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_TASK_DETAIL, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_TASK_DETAIL, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取返利兑换类型
     */
    public static void getExchangeType(final Context context,
            ApiRequestListener handler) {


        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_TYPE, handler, null).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_TYPE, handler, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取返利兑换物品
     */
    public static void getExchangeGoods(final Context context,
            ApiRequestListener handler, int type) {

        final HashMap<String, Object> params = new HashMap<String, Object>(2);

        params.put("goods_type_id", type);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_GOODS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_GOODS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取返利兑换明细
     */
    public static void getExchangeDetail(final Context context,
            ApiRequestListener handler, int startPosition, int size) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(4);

        params.put("imei", mSession.getIMEI());
        params.put("mac", mSession.getMac());
        params.put("start_position", startPosition);
        params.put("size", size);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_DETAIL, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_DETAIL, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取返利收入明细
     */
    public static void getExchangeReward(final Context context,
            ApiRequestListener handler, int startPosition, int size) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(2);

        params.put("imei", mSession.getIMEI());
        params.put("mac", mSession.getMac());
        params.put("start_position", startPosition);
        params.put("size", size);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_REWARD, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_EXCHANGE_REWARD, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 返利兑换
     */
    public static void exchange(final Context context,
            ApiRequestListener handler, String id) {

        final HashMap<String, Object> params = new HashMap<String, Object>(2);

        params.put("goods_id", id);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_EXCHANGE, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_EXCHANGE, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }


    /**
     * 获得搜索关键词推荐
     */
    public static void getSearchRecommend(final Context context, ApiRequestListener handler,
            String keywords) {

        new ApiAsyncTask(context, ACTION_GET_SEARCH_RECOMMEND, handler, keywords).execute();
    }


    public static ApiRequest getSearchRecommend(Context context,
            String keyword) {

        ApiRequest request = null;
        try {
            request = new ApiRequest.Builder(context, ApiRequest.POST,
                    ACTION_GET_SEARCH_RECOMMEND).addParameter("q", keyword).build();
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return request;
    }

    /**
     * Get Search Keywords API<br>
     * Default size is 10.
     */
    public static void getSearchKeywords(final Context context, ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);

        params.put("size", 100);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_SEARCH_KEYWORDS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_SEARCH_KEYWORDS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取推送的消息
     */
    public static void getPushMessage(final Context context, ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        // 1 手机 2 Pad
        params.put("device_type", "1");
        params.put("last_update_time", session.getLastPushMessageTime());
        // 是否忽略广播类消息（某些设备制造商不希望接收机锋的活动消息） 0:不忽略 1:忽略
        params.put("skip_broadcast", "0");

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_MESSAGE, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_MESSAGE, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * IFTTT回报
     *
     * @param nid        推条ID
     * @param rule       推条规则
     * @param reportType 报告类型 0:弹出通知 1:浏览详情 2:下载应用
     */
    public static void reportIftttResult(final Context context, String pid, String nid,
            String rule, int reportType) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);

        Session session = Session.get(context);

        String uid = TextUtils.isEmpty(session.getUid()) ? "-1" : session.getUid();
        params.put("uid", uid);
        params.put("p_id", pid);
        params.put("nid", nid);
        params.put("rule", rule);
        params.put("cpid", session.getCpid());
        params.put("report_type", reportType);
        params.put("package_name", session.getPackageName());

        new ApiAsyncTask(context, ACTION_IFTTT_REPORT, null, params).execute();
    }

    /**
     * 获得首页的达人推荐专题
     */
    public static void getHomeMasterRecommend(final Context context, ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);

        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_HOME_MASTER_RECOMMEND, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_HOME_MASTER_RECOMMEND, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 标记新的应用已读
     */
    public static void markFollowedRead(final Context context, String topicId,
            ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("promotion_id", topicId);
        String uid = TextUtils.isEmpty(session.getUid()) ? "-1" : session.getUid();
        params.put("uid", uid);
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_MARK_READ, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_MARK_READ, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取已关注的达人专题
     */
    public static void getFollowedRecommend(final Context context, ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        String uid = TextUtils.isEmpty(session.getUid()) ? "-1" : session.getUid();
        params.put("uid", uid);
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_FOLLOWED_RECOMMEND, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_FOLLOWED_RECOMMEND, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 关注达人推荐的主题
     *
     * @param flag 1 关注 0 不关注
     */
    public static void requestFollowMaster(Context context, ApiRequestListener handler,
            String promotionId, String flag) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        Session session = Session.get(context);

        String uid = TextUtils.isEmpty(session.getUid()) ? "-1" : session.getUid();
        params.put("uid", uid);
        params.put("promotion_id", promotionId);
        params.put("follow_flag", flag);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_FOLLOW_MASTER, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_FOLLOW_MASTER, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 查询达人推荐专题的关注状态
     */
    public static void queryFoolowStatus(Context context, ApiRequestListener handler,
            String promotionId) {
        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        Session session = Session.get(context);

        String uid = TextUtils.isEmpty(session.getUid()) ? "-1" : session.getUid();
        params.put("uid", uid);
        params.put("promotion_id", promotionId);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_FOLLOW_MASTER, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_FOLLOW_MASTER, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    public static void getSearchFromBBS(final Context context, ApiRequestListener handler,
            String keyword, int start, int size) {

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("searchWord", keyword));
        params.add(new BasicNameValuePair("startPosition", String.valueOf(start)));
        params.add(new BasicNameValuePair("size", String.valueOf(size)));

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_BBS_SEARCH, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_BBS_SEARCH, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 装机必备API<br>
     */
    public static void getRequired(final Context context, ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);

        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_REQUIRED, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_REQUIRED, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 通知栏推荐API<br>
     */
    public static void getNotificationRecommend(final Context context, ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);

        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("device_type", "1");
        params.put("rule_support", "1");
        params.put("last_update_time", session.getLastNotificationTime());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_RECOMMEND_NOTIFICATION, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_RECOMMEND_NOTIFICATION, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * Get Home Page Top Recommends API<br>
     * Default size is 10.
     */
    public static void getTopRecommend(final Context context, ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);

        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);
        params.put("device_type", "5");

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_TOP_RECOMMEND, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_TOP_RECOMMEND, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * Get All Category API<br>
     */
    public static void getAllCategory(final Context context, ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);

        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_ALL_CATEGORY, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_ALL_CATEGORY, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * Register API<br>
     * Do the register process, UserName, Password, Email must be provided.<br>
     */
    public static void register(final Context context, ApiRequestListener handler, String username,
            String password, String email) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);

        params.put("username", username);
        params.put("password", password);
        params.put("email", email);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_REGISTER, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_REGISTER, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * Login API<br>
     * Do the login process, UserName, Password must be provided.<br>
     */
    public static void login(final Context context, ApiRequestListener handler, String username,
            String password) {

        final HashMap<String, Object> params = new HashMap<String, Object>(2);

        params.put("username", username);
        params.put("password", password);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_LOGIN, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_LOGIN, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }
    
    public static void thirdLogin(final Context context, ApiRequestListener handler, String username,
            int type, String thirduid) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);

        params.put("username", username);
        params.put("type", type);
        params.put("thirduid", thirduid);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_THRID_LOGIN, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_THRID_LOGIN, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
	}

	public static void getHistoryInstall(final Context context,
			ApiRequestListener handler, String uid, int startPosition, int size) {

        final HashMap<String, Object> params = new HashMap<String, Object>(6);
        Session session = Session.get(context);
        // TODO delete this
        if(TextUtils.isEmpty(uid)) {
        	uid = "1";
        }
        params.put("uid", uid);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_HISTORY_INSTALL, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_HISTORY_INSTALL, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }
    

    public static void insertHistoryInstall(final Context context, ApiRequestListener handler, String pkgs) {

		final HashMap<String, Object> params = new HashMap<String, Object>(1);
		Session session = Session.get(context);
		// TODO delete this
		params.put("uid", session.getUid());
		System.out.println("============================uid = " + session.getUid());
//		params.put("uid", "1");
		params.put("pkgs", pkgs);

		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
			new ApiAsyncTask(context, ACTION_INSERT_HISTORY_INSTALL, handler,
					params).execute();
		} else {
			new ApiAsyncTask(context, ACTION_INSERT_HISTORY_INSTALL, handler,
					params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
		}
	}

    /**
     * Get Home Recommend API<br>
     * 首页推荐列表（包含编辑推荐部分和算法生成部分）<br>
     *
     * @param isForSearch 搜索无结果时的补全结果
     */
    public static void getHomeRecommend(final Context context, ApiRequestListener handler,
            int startPosition, int size, boolean isForSearch) {

        Session session = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(5);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);
        if (isForSearch) {
            params.put("recommend_type", Constants.ARC);
        }

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_HOME_RECOMMEND, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_HOME_RECOMMEND, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 汉化专区首页推荐<br>
     */
    public static void getLocalRecommend(final Context context, ApiRequestListener handler,
            int startPosition, int size) {

        Session session = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(5);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);
        params.put("source_type", "3");

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_HOME_RECOMMEND, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_HOME_RECOMMEND, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 汉化专区首页推荐<br>
     */
    public static ApiAsyncTaskLoader initLocalRecommend(Context context,
            int startPosition, int size) {
        try {
            Session mSession = Session.get(context);

            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_HOME_RECOMMEND)
                    .addParameter("size", size)
                    .addParameter("start_position", startPosition)
                    .addParameter("platform", mSession.getOsVersion())
                    .addParameter("screen_size", mSession.getScreenSize())
                    .addParameter("match_type", mSession.isFilterApps())
                    .addParameter("feature_type", "cpu")
                    .addParameter("feature", Constants.ARC)
                    .addParameter("recommend_type", "2")
                    .addParameter("source_type", "3").build();

            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * Get Rank By Category API<br>
     * 首页排行列表<br>
     */
    public static void getRankByCategory(final Context context, ApiRequestListener handler,
            int startPosition, int size, String category) {

        Session session = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(6);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("category", category);
        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        // 加入成长型风向标算法
        params.put("orderby", 4);
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_RANK_BY_CATEGORY, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_RANK_BY_CATEGORY, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 汉化分类排行<br>
     */
    public static void getRankByCategoryV2(Context context, ApiRequestListener handler,
            int startPosition, int size, String category) {

        Session session = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(6);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("category", category);
        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        // 加入成长型风向标算法
        params.put("orderby", 4);
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);
        params.put("source_type", "3");

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_RANK_BY_CATEGORY, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_RANK_BY_CATEGORY, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 排行，汉化
     * <hr>
     * 包括排行的子分类，游戏，应用，电子书。
     * <br>
     * 包括汉化的子分类，汉化游戏，汉化应用。
     * <br>
     *
     * @param isLocalization 如果为true，则请求结果是汉化的。
     *                       如果为false,则请求结果是为汉化的。
     * @return
     */
    public static ApiAsyncTaskLoader initRankByCategoryLoader(Context context,
            int startPosition, int size, String category, boolean isLocalization) {
        try {
            Session mSession = Session.get(context);

            ApiRequest.Builder builder = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_RANK_BY_CATEGORY)
                    .addParameter("size", size)
                    .addParameter("start_position", startPosition)
                    .addParameter("category", category)
                    .addParameter("platform", mSession.getOsVersion())
                    .addParameter("screen_size", mSession.getScreenSize())
                    .addParameter("match_type", mSession.isFilterApps())
                    .addParameter("feature_type", "cpu")
                    .addParameter("feature", Constants.ARC)
                    .addParameter("orderby", 4);
            if (isLocalization) {
                builder.addParameter("source_type", "3");
            }
            ApiRequest request = builder.build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 汉化分类排行<br>
     * 默认为汉化
     */
    public static ApiAsyncTaskLoader initRankByCategoryLoader(Context context,
            int startPosition, int size, String category) {
        return initRankByCategoryLoader(context, startPosition, size, category,
                true);
    }

    /**
     * 汉化分类排行<br>
     */
    public static ApiAsyncTaskLoader intLocalRankByCategoryLoader(final Context context, ApiRequestListener handler,
            int startPosition, int size, String category) {

        try {
            Session mSession = Session.get(context);
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_RANK_BY_CATEGORY)
                    .addParameter("size", size)
                    .addParameter("start_position", startPosition)
                    .addParameter("category", category)
                    .addParameter("platform", mSession.getOsVersion())
                    .addParameter("screen_size", mSession.getScreenSize())
                    .addParameter("match_type", mSession.isFilterApps())
                    .addParameter("feature_type", "cpu")
                    .addParameter("feature", Constants.ARC)
                    .addParameter("source_type", "3").build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;
    }


    public static ApiAsyncTaskLoader initGetRankLoaderByCategory(Context context,
            int size, int startPosition, String category) {

        try {
            Session mSession = Session.get(context);
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_RANK_BY_CATEGORY)
                    .addParameter("size", size)
                    .addParameter("start_position", startPosition)
                    .addParameter("category", category)
                    .addParameter("platform", mSession.getOsVersion())
                    .addParameter("screen_size", mSession.getScreenSize())
                    .addParameter("match_type", mSession.isFilterApps())
                    .addParameter("feature_type", "cpu")
                    .addParameter("orderby", 4)
                    .addParameter("feature", Constants.ARC).build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * Get Grow Fast API<br>
     * 增长最快排行列表<br>
     */
    public static void getGrowFast(final Context context, ApiRequestListener handler,
            int startPosition, int size) {

        Session session = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(5);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_GROW_FAST, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_GROW_FAST, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * Get Paid Rank API<br>
     * 收费排行列表<br>
     */
    public static void getPaidRank(final Context context, ApiRequestListener handler,
            int startPosition, int size) {

        Session session = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(5);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_PAID_RANK, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_PAID_RANK, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * Bind user account with cloud authority
     */
    public static void bindAccount(final Context context, ApiRequestListener handler) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(4);
        params.put("uid", mSession.getUid());
        params.put("devid", mSession.getDeviceId());
        params.put("imei", mSession.getIMEI());
        params.put("phonemodel", mSession.getModel());
        // use new hudee system
        params.put("version", 2);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_BIND_ACCOUNT, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_BIND_ACCOUNT, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * Unbind user account with cloud authority
     */
    public static void unbindAccount(final Context context, ApiRequestListener handler) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_UNBIND, handler, null).execute();
        } else {
            new ApiAsyncTask(context, ACTION_UNBIND, handler, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取专题推荐商品列表
     */
    public static void getRecommendProducts(final Context context, ApiRequestListener handler,
            String type, int size, int startPosition) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(6);
        params.put("type", type);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("platform", mSession.getOsVersion());
        params.put("screen_size", mSession.getScreenSize());
        params.put("match_type", mSession.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_RECOMMEND_PRODUCTS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_RECOMMEND_PRODUCTS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取专题推荐商品列表
     */
    public static ApiAsyncTaskLoader initGetRecommendProductsLoader(final Context context,
            String type, int size, int startPosition) {
        try {
            Session mSession = Session.get(context);
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_RECOMMEND_PRODUCTS)
                    .addParameter("type", type)
                    .addParameter("size", size)
                    .addParameter("start_position", startPosition)
                    .addParameter("platform", mSession.getOsVersion())
                    .addParameter("screen_size", mSession.getScreenSize())
                    .addParameter("match_type", mSession.isFilterApps())
                    .addParameter("feature_type", "cpu")
                    .addParameter("feature", Constants.ARC).build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取应用分类列表
     */
    public static void getCategory(final Context context, ApiRequestListener handler,
            String categoryCode) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(5);
        params.put("local_version", -1);
        params.put("category_cord", categoryCode);
        params.put("platform", mSession.getOsVersion());
        params.put("screen_size", mSession.getScreenSize());
        params.put("match_type", mSession.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_CATEGORY, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_CATEGORY, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }


    public static ApiAsyncTaskLoader initGetProductsLoader(Context context,
            int size, int startPosition, int orderBy, String categoryId) {

        try {
            Session mSession = Session.get(context);
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_PRODUCTS)
                    .addParameter("size", size)
                    .addParameter("start_position", startPosition)
                    .addParameter("orderby", orderBy)
                    .addParameter("category_id", categoryId)
                    .addParameter("platform", mSession.getOsVersion())
                    .addParameter("screen_size", mSession.getScreenSize())
                    .addParameter("match_type", mSession.isFilterApps())
                    .addParameter("feature_type", "cpu")
                    .addParameter("feature", Constants.ARC).build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            Utils.D(">>>>>>>>>>RequestBuildException");
        }
        return null;
    }

    /**
     * 获取应用列表
     */
    public static void getProducts(final Context context, ApiRequestListener handler, int size,
            int startPosition, int orderBy, String categoryId) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(6);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("platform", mSession.getOsVersion());
        params.put("screen_size", mSession.getScreenSize());
        params.put("orderby", orderBy);
        params.put("category_id", categoryId);
        params.put("match_type", mSession.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_PRODUCTS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_PRODUCTS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取评论
     */
    public static void getComments(final Context context, ApiRequestListener handler, String pId,
            int size, int startPosition) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);
        params.put("p_id", pId);
        params.put("size", size);
        params.put("start_position", startPosition);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_COMMENTS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_COMMENTS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取评论列表
     */
    public static ApiAsyncTaskLoader initGetCommentsLoader(final Context context,
            String pId, int size, int startPosition) {

        try {
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_COMMENTS)
                    .addParameter("p_id", pId)
                    .addParameter("size", size)
                    .addParameter("start_position", startPosition)
                    .build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            Utils.D(">>>>>>>>>>RequestBuildException", e);
        }
        return null;
    }

    /**
     * 充值
     */
    public static void charge(final Context context, ApiRequestListener handler, String password,
            String type, CardInfo card) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(7);
        params.put("user_id", mSession.getUid());
        params.put("password",
                SecurityUtil.encryptPassword(password, String.valueOf(mSession.getUid())));
        params.put("type", type);
        params.put("pay_type", card.payType);
        params.put("card_account", card.cardAccount);
        params.put("card_password", card.cardPassword);
        params.put("card_credit", card.cardCredit);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_CHARGE, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_CHARGE, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 添加评论
     */
    public static void addComment(final Context context, ApiRequestListener handler, String pId,
            String comment) {

        Session mSession = Session.get(context);

        String passwordEnc = SecurityUtil.encryptPassword(mSession.getPassword(),
                mSession.getUserName());
        String verifyCodeEnc = Utils.getUTF8String(Base64.encodeBase64(DigestUtils.md5(String
                .valueOf(mSession.getUserName()) + String.valueOf(pId) + passwordEnc)));

        final HashMap<String, Object> params = new HashMap<String, Object>(3);
        params.put("p_id", pId);
        params.put("uid", mSession.getUid());
        params.put("comment", comment);
        params.put("username", mSession.getUserName());
        params.put("password", passwordEnc);
        params.put("verify_code", verifyCodeEnc);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_ADD_COMMENT, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_ADD_COMMENT, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 添加评论
     */
    public static ApiAsyncTaskLoader initAddCommentsLoader(final Context context,
            String pId, String comment) {

        Session mSession = Session.get(context);

        String passwordEnc = SecurityUtil.encryptPassword(mSession.getPassword(),
                mSession.getUserName());
        String verifyCodeEnc = Utils.getUTF8String(Base64.encodeBase64(DigestUtils.md5(String
                .valueOf(mSession.getUserName()) + String.valueOf(pId) + passwordEnc)));

        try {
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_ADD_COMMENT)
                    .addParameter("p_id", pId)
                    .addParameter("uid", mSession.getUid())
                    .addParameter("comment", comment)
                    .addParameter("username", mSession.getUserName())
                    .addParameter("password", passwordEnc)
                    .addParameter("verify_code", verifyCodeEnc)
                    .build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            Utils.D(">>>>>>>>>>RequestBuildException", e);
        }
        return null;
    }

    /**
     * 添加评级
     */
    public static void addRating(final Context context, ApiRequestListener handler, String pId,
            int rating) {

        Session mSession = Session.get(context);

        String passwordEnc = SecurityUtil.encryptPassword(mSession.getPassword(),
                mSession.getUserName());
        String verifyCodeEnc = Utils.getUTF8String(Base64.encodeBase64(DigestUtils.md5(String
                .valueOf(mSession.getUserName()) + String.valueOf(pId) + passwordEnc)));
        final HashMap<String, Object> params = new HashMap<String, Object>(6);
        params.put("p_id", pId);
        params.put("uid", mSession.getUid());
        params.put("rating", rating);
        params.put("username", mSession.getUserName());
        params.put("password", passwordEnc);
        params.put("verify_code", verifyCodeEnc);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_ADD_RATING, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_ADD_RATING, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 添加评级
     */
    public static ApiAsyncTaskLoader initAddRatingLoader(final Context context,
            String pId, int rating) {

        Session mSession = Session.get(context);

        String passwordEnc = SecurityUtil.encryptPassword(mSession.getPassword(),
                mSession.getUserName());
        String verifyCodeEnc = Utils.getUTF8String(Base64.encodeBase64(DigestUtils.md5(String
                .valueOf(mSession.getUserName()) + String.valueOf(pId) + passwordEnc)));

        try {
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_ADD_RATING)
                    .addParameter("p_id", pId)
                    .addParameter("uid", mSession.getUid())
                    .addParameter("rating", rating)
                    .addParameter("username", mSession.getUserName())
                    .addParameter("password", passwordEnc)
                    .addParameter("verify_code", verifyCodeEnc)
                    .build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            Utils.D(">>>>>>>>>>RequestBuildException", e);
        }
        return null;
    }

    /**
     * 购买商品
     */
    public static void purchaseProduct(final Context context, ApiRequestListener handler,
            String pId, String password) {

        Session mSession = Session.get(context);

        String passwordEnc = SecurityUtil.encryptPassword(password, mSession.getUserName());
        String verifyCodeEnc = Utils.getUTF8String(Base64.encodeBase64(DigestUtils.md5(String
                .valueOf(mSession.getUserName()) + String.valueOf(pId) + passwordEnc)));

        final HashMap<String, Object> params = new HashMap<String, Object>(4);
        params.put("pid", pId);
        params.put("username", mSession.getUserName());
        params.put("password", passwordEnc);
        params.put("verify_code", verifyCodeEnc);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_PURCHASE_PRODUCT, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_PURCHASE_PRODUCT, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取下载链接
     */
    public static void getDownloadUrl(final Context context, ApiRequestListener handler,
            String pId, String sourceType, String... args) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(3);
        params.put("p_id", pId);
        params.put("uid", mSession.getUid());
        params.put("source_type", sourceType);
        if (args != null && args.length > 0) {
            String pkgName = args[0];
            HashMap<String, Object> item = mSession.mPreloadInstalled.get(pkgName);
            if (item != null) {
                params.put("rsa_md5", item.get(Constants.KEY_PRODUCT_RSA_MD5));
            }
        }

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_DOWNLOAD_URL, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_DOWNLOAD_URL, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取下载链接
     */
    public static ApiAsyncTaskLoader initGetDownloadInfoLoader(final Context context,
            String pId, String sourceType) {

        Session mSession = Session.get(context);

        try {
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_DOWNLOAD_URL)
                    .addParameter("p_id", pId)
                    .addParameter("uid", mSession.getUid())
                    .addParameter("source_type", sourceType)
                    .build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            Utils.D(">>>>>>>>>>RequestBuildException", e);
        }
        return null;
    }

    /**
     * 搜索
     */
    public static void search(final Context context, ApiRequestListener handler, int size,
            int startPosition, int orderBy, String keyword) {

        Session session = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(7);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("orderby", orderBy);
        params.put("keyword", keyword);
        params.put("match_type", session.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_SEARCH, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_SEARCH, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取商品详细信息
     */
    public static void getProductDetailWithId(final Context context, ApiRequestListener handler,
            int localVersion, String pId, String sourceType) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);
        params.put("local_version", localVersion);
        params.put("p_id", pId);
        params.put("source_type", sourceType);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_PRODUCT_DETAIL, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_PRODUCT_DETAIL, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取商品详细信息(产品ID)
     */
    public static ApiAsyncTaskLoader initProductDetailWithPId(Context context,
            String pId, String sourceType) {

        try {
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_PRODUCT_DETAIL)
                    .addParameter("local_version", -1)
                    .addParameter("p_id", pId)
                    .addParameter("source_type", sourceType).build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取商品详细信息(包名)
     */
    public static void getProductDetailWithPackageName(final Context context,
            ApiRequestListener handler, int localVersion, String packageName) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);
        params.put("local_version", localVersion);
        params.put("packagename", packageName);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_DETAIL, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_DETAIL, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取商品详细信息(包名)
     */
    public static ApiAsyncTaskLoader initProductDetailWithPackageName(Context context,
            String packageName, String sourceType) {

        try {
            Session session = Session.get(context);
//            ApiRequest request = new ApiRequest.Builder(context,
//                    ApiRequest.POST, ACTION_GET_DETAIL)
//                    .addParameter("local_version", -1)
//                    .addParameter("source_type", sourceType)
//                    .addParameter("rsa_md5", (String) session.mPreloadInstalled
//                            .get(packageName).get(Constants.KEY_PRODUCT_RSA_MD5))
//                    .addParameter("packagename", packageName).build();
            
            ApiRequest.Builder builder = new ApiRequest.Builder(context, 
                    ApiRequest.POST, ACTION_GET_DETAIL);
            
            builder.addParameter("local_version", -1)
                    .addParameter("source_type", sourceType)
                    .addParameter("packagename", packageName);
            
            if (session.mPreloadInstalled != null
                    && session.mPreloadInstalled.get(packageName) != null
                    && session.mPreloadInstalled.get(packageName)
                            .get(Constants.KEY_PRODUCT_RSA_MD5) != null) {
                //fix bug by chaos at 2013/3/18
                //修复了导致程序多处崩溃的Bug
                //XXX 如果不是已安装应用，则不传递MD5.
                //notice:
                //目前必须传递MD5的接口有：汉化下所有列表必须传递MD5，已安装应用必须
                //传递MD5.对于以上必须传递MD5的地方，也可以通过initProductDetailWithPId(int pid)
                //接口来规避传递MD5.
                builder.addParameter("rsa_md5", (String) session.mPreloadInstalled.get(packageName)
                        .get(Constants.KEY_PRODUCT_RSA_MD5));
            }
            
            
            return new ApiAsyncTaskLoader(context, builder.build());
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取消费总额
     */
    public static void getConsumeSum(final Context context, ApiRequestListener handler, String uId) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        params.put("uid", uId);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_CONSUMESUM, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_CONSUMESUM, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 同步用户购买记录
     */
    public static void syncBuyLog(final Context context, ApiRequestListener handler) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        params.put("uid", mSession.getUid());

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_SYNC_BUYLOG, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_SYNC_BUYLOG, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取我的评级
     */
    public static void getMyRating(final Context context, ApiRequestListener handler, String pId) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(2);
        params.put("uid", mSession.getUid());
        params.put("p_id", pId);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_MYRATING, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_MYRATING, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取我的评级
     */
    public static ApiAsyncTaskLoader initGetRatingLoader(Context context, String pid) {

        Session mSession = Session.get(context);
        try {
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_MYRATING)
                    .addParameter("uid", mSession.getUid())
                    .addParameter("p_id", pid).build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;

    }

    /**
     * 查询充值结果
     */
    public static void queryChargeResult(final Context context, ApiRequestListener handler,
            String orderId) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        params.put("order_id", orderId);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_QUERY_CHARGE_BY_ORDERID, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_QUERY_CHARGE_BY_ORDERID, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 同步充值卡信息
     */
    public static void syncCardInfo(final Context context, ApiRequestListener handler) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        params.put("local_version", mSession.getCreditCardVersion());

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_SYNC_CARDINFO, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_SYNC_CARDINFO, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取消费明细
     */
    public static void getConsumeDetail(final Context context, ApiRequestListener handler,
            String uid, String type) {

        final HashMap<String, Object> params = new HashMap<String, Object>(2);
        params.put("uid", uid);
        params.put("type", type);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_CONSUME_DETAIL, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_CONSUME_DETAIL, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取专题列表
     */
    public static void getTopic(final Context context, ApiRequestListener handler) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(4);
        params.put("platform", mSession.getOsVersion());
        params.put("screen_size", mSession.getScreenSize());
        params.put("match_type", mSession.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_TOPIC, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_TOPIC, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 检查更新（机锋市场）
     */
    public static void checkUpdate(final Context context, ApiRequestListener handler) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(4);
        params.put("package_name", mSession.getPackageName());
        params.put("version_code", mSession.getVersionCode());
        params.put("sdk_id", mSession.getCpid());
        params.put("type", mSession.getDebugType());

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_CHECK_NEW_VERSION, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_CHECK_NEW_VERSION, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 检查更新（应用）
     */
    public static void checkUpgrade(final Context context, ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        params.put("upgradeList", Session.get(context).getInstalledAppsInfo());

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_CHECK_UPGRADE, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_CHECK_UPGRADE, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 查询余额
     */
    public static void getBalance(Context context, ApiRequestListener handler) {
        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        params.put("uid", mSession.getUid());

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_BALANCE, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_BALANCE, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 查询充值支付记录
     */
    public static void getPayLog(Context context, ApiRequestListener handler, int newStartPosition,
            int size) {
        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(3);
        params.put("uid", mSession.getUid());
        params.put("start_position", newStartPosition);
        params.put("size", size);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_PAY_LOG, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_PAY_LOG, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 检查是否有新splash需要下载
     */
    public static void checkNewSplash(Context context, ApiRequestListener handler) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(4);
        params.put("package_name", mSession.getPackageName());
        params.put("version_code", mSession.getVersionCode());
        params.put("sdk_id", mSession.getCpid());
        params.put("time", mSession.getSplashTime());

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_CHECK_NEW_SPLASH, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_CHECK_NEW_SPLASH, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取支付宝订单信息
     */
    public static void getAliPayOrder(final Context context, ApiRequestListener handler, int money,
            String productName, String productDesc) {
        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(4);
        params.put("uid", Utils.getInt(mSession.getUid()));
        params.put("money", money);
        params.put("productName", productName);
        params.put("productDesc", productDesc);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_ALIPAY_ORDER_INFO, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_ALIPAY_ORDER_INFO, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 查询支付宝充值结果
     */
    public static void queryAliPayResult(final Context context, ApiRequestListener handler,
            String orderId) {
        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        params.put("orderNo", orderId);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_QUERY_ALIPAY_RESULT, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_QUERY_ALIPAY_RESULT, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 提交所有应用
     */
    public static void submitAllInstalledApps(final Context context) {
        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        params.put("appList", "");
        new ApiAsyncTask(context, ACTION_SYNC_APPS, null, params).execute();
    }

    /**
     * 检查Log提交级别
     */
    public static void checkLogLevel(final Context context, ApiRequestListener handler) {

        String[] modules = new String[]{Constants.MOBILE_DOWNLOAD, Constants.MOBILE_CRASH};
        new ApiAsyncTask(context, ACTION_CHECK_LOG_LEVEL, handler, modules).execute();
    }

    /**
     * 提交客户端的统计Log
     */
    public static void submitLogs(final Context context, final int level, final String module) {

        final HashMap<String, Object> params = new HashMap<String, Object>(2);
        params.put("module", module);
        params.put("level", level);
        new ApiAsyncTask(context, ACTION_INSERT_LOG, new ApiRequestListener() {

            @Override
            public void onSuccess(int method, Object obj) {
                // del the log
                DBUtils.delLogs(context, module, level);
            }

            @Override
            public void onError(int method, int statusCode) {
                // do nothing
            }
        }, params).execute();
    }

    /**
     * 获取玩家推荐列表
     */
    public static void getMasterRecommend(final Context context,
            ApiRequestListener handler, int size, int startPosition) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);
        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        new ApiAsyncTask(context, ACTION_GET_MASTER_RECOMMEND, handler, params)
                .execute();
    }

    /**
     * 在详情页获取标签信息
     */
    public static ApiAsyncTaskLoader initMaterRecommendLoader(Context context, int size,
            int startPosition) {

        try {
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_MASTER_RECOMMEND)
                    .addParameter("size", size)
                    .addParameter("start_position", startPosition)
                    .build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;

    }

    /**
     * 获取玩家推荐详细
     */
    public static void getMasterRecommendApps(final Context context, ApiRequestListener handler,
            int size, int startPosition, String promotionId) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(6);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("platform", mSession.getOsVersion());
        params.put("screen_size", mSession.getScreenSize());
        params.put("promotion_id", promotionId);
        params.put("match_type", mSession.isFilterApps());
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_MASTER_RECOMMEND_APPS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_MASTER_RECOMMEND_APPS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取玩家推荐的讨论列表
     */
    public static void getMasterRecommendDiscuss(final Context context, ApiRequestListener handler,
            int size, int startPosition, String promotionId) {

        final HashMap<String, Object> params = new HashMap<String, Object>(3);
        params.put("size", size);
        params.put("start_position", startPosition);
        params.put("promotion_id", promotionId);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_DISCUSS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_DISCUSS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 添加玩家推荐的讨论
     */
    public static void addMasterRecommendDiscuss(final Context context, ApiRequestListener handler,
            String promotionId, String content) {

        Session mSession = Session.get(context);

        String passwordEnc = SecurityUtil.encryptPassword(mSession.getPassword(),
                mSession.getUserName());
        String verifyCodeEnc = Utils.getUTF8String(Base64.encodeBase64(DigestUtils.md5(String
                .valueOf(mSession.getUserName()) + promotionId + passwordEnc)));

        final HashMap<String, Object> params = new HashMap<String, Object>(6);
        params.put("uid", mSession.getUid());
        params.put("content", content);
        params.put("promotion_id", promotionId);
        params.put("username", mSession.getUserName());
        params.put("password", passwordEnc);
        params.put("verify_code", verifyCodeEnc);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_ADD_DISCUSS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_ADD_DISCUSS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 添加玩家推荐的评级
     */
    public static void addMasterRecommendRating(final Context context, ApiRequestListener handler,
            int rating, String promotionId) {

        final HashMap<String, Object> params = new HashMap<String, Object>(2);
        params.put("promotion_id", promotionId);
        params.put("rating", rating);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_ADD_RECOMMEND_RATING, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_ADD_RECOMMEND_RATING, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取玩家推荐的评级
     */
    public static void getMasterRecommendRating(final Context context, ApiRequestListener handler,
            String promotionId) {

        final HashMap<String, Object> params = new HashMap<String, Object>(1);
        params.put("promotion_id", promotionId);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_RECOMMEND_RATING, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_RECOMMEND_RATING, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 提交下载状态日志
     */
    public static void submitDownloadLog(final Context context, ApiRequestListener handler,
            String pId, String sourceType, String url, String ip, String network, int reportType,
            String packageName, long size) {

        Session mSession = Session.get(context);

        final HashMap<String, Object> params = new HashMap<String, Object>(8);
        String uid = mSession.getUid();
        if (TextUtils.isEmpty(uid)) {
            uid = "-1";
        }
        params.put("uid", uid);
        params.put("p_id", pId);
        params.put("source_type", sourceType);
        params.put("url", url);
        params.put("ip", ip);
        params.put("cpid", mSession.getCpid());
        params.put("net_context", network);
        params.put("report_type", reportType);
        params.put("package_name", packageName);
        params.put("size", size);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_DOWN_REPORT, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_DOWN_REPORT, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获取产品详细页 ，发现tab中，收录应用达人信息
     */
    public static void getMasterContains(final Context context, ApiRequestListener handler, String pId) {

        final HashMap<String, Object> params = new HashMap<String, Object>(4);
        Session session = Session.get(context);
        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("p_id", pId);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_MASTER_CONTAINS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_MASTER_CONTAINS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 与应用相关的推荐列表API
     */
    public static void getRecommendByApp(final Context context, ApiRequestListener handler, String pId) {

        final HashMap<String, Object> params = new HashMap<String, Object>(4);

        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("p_id", pId);
        params.put("feature_type", "cpu");
        params.put("feature", Constants.ARC);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_RECOMMEND_BY_APP, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_RECOMMEND_BY_APP, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    public static ApiAsyncTaskLoader initRecommendByAppLoader(Context context,
            String pid) {

        try {
            Session mSession = Session.get(context);
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_RECOMMEND_BY_APP)
                    .addParameter("p_id", pid).build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 在详情页获取标签信息
     */
    public static ApiAsyncTaskLoader initTagsByApp(Context context, String pid) {

        try {
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_TAGS_IN_DETAILS)
                    .addParameter("p_id", pid).build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 猜你喜欢
     */
    public static ApiAsyncTaskLoader initRecommendByUserLoader(Context context,
            int size, int startPosition) {
        try {
            Session mSession = Session.get(context);
            ApiRequest request = new ApiRequest.Builder(context,
                    ApiRequest.POST, ACTION_GET_RECOMMEND_BY_APP)
//                    .addParameter("size", size)
//                    .addParameter("start_position", startPosition)
                    .addParameter("platform", mSession.getOsVersion())
                    .addParameter("screen_size", mSession.getScreenSize())
                    .addParameter("match_type", mSession.isFilterApps())
                    .addParameter("p_id", mSession.getTopPid())
                    .build();
            return new ApiAsyncTaskLoader(context, request);
        } catch (ApiRequest.RequestBuildException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获得标签列表
     */
    public static void getCategoryTags(final Context context, ApiRequestListener handler) {

        final HashMap<String, Object> params = new HashMap<String, Object>(4);

        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_CATEGORY_TAGS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_CATEGORY_TAGS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 获得标签详情页
     *
     * @param context
     * @param handler
     * @param size
     * @param startPosition
     * @param tagsId
     */
    public static void getCategoryTagsDetails(final Context context, ApiRequestListener handler,
            int size, int startPosition, String tagsId) {

        final HashMap<String, Object> params = new HashMap<String, Object>(4);

        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("size", size);
        params.put("tag_id", tagsId);
        params.put("start_position", startPosition);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_TAGS_DETAILS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_TAGS_DETAILS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    /**
     * 在详情页获取标签信息
     *
     * @param context
     * @param handler
     * @param pid
     */
    public static void getCategoryTagsInDetails(final Context context, ApiRequestListener handler,
            String pid) {
        final HashMap<String, Object> params = new HashMap<String, Object>(4);

        Session session = Session.get(context);

        params.put("platform", session.getOsVersion());
        params.put("screen_size", session.getScreenSize());
        params.put("match_type", session.isFilterApps());
        params.put("p_id", pid);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            new ApiAsyncTask(context, ACTION_GET_TAGS_IN_DETAILS, handler, params).execute();
        } else {
            new ApiAsyncTask(context, ACTION_GET_TAGS_IN_DETAILS, handler, params).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

}